package com.example.wang.ghtoonui;

import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.example.wang.ghtoonui.homepage.FrescoImageLoader;
import com.example.wang.ghtoonui.homepage.GHHomepageFragment;
import com.jaeger.library.StatusBarUtil;
import com.orhanobut.logger.Logger;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity implements OnBannerListener{

    //横幅需要填充的url数据
    List<String> bannerUrlList;

    //横幅视图
    Banner banner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        StatusBarUtil.setColor(MainActivity.this, getResources().getColor(R.color.colorPrimary));
//        initView();
        Fragment fragment = getSupportFragmentManager().findFragmentById(android.R.id.content);
        if(fragment == null){
            fragment = GHHomepageFragment.newInstance();
            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(android.R.id.content, fragment, "")
                    .commit();

        } else {
            getSupportFragmentManager()
                    .beginTransaction()
                    .attach(fragment)
                    .commit();
        }

    }

    private void initView() {
        initBannerData();
        banner = (Banner) findViewById(R.id.banner);
        banner.setImages(bannerUrlList)
                .setImageLoader(new FrescoImageLoader())
                .start();
        banner.setOnBannerListener(this);

    }

    private void initBannerData() {
        String [] urls = getResources().getStringArray(R.array.urls);
        bannerUrlList = Arrays.asList(urls);
    }

    @Override
    public void OnBannerClick(int position) {
        Logger.d("position is " + position);
    }
}
